package com.java47.util;
import java.text.SimpleDateFormat;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class Util {
    //重载
    public static String getJson(Object obj) {
        return getJson(obj,"yyyy-MM-dd HH:mm:ss");
    }


    public static String getJson(Object obj,String dateFormat) {

        ObjectMapper mapper = new ObjectMapper();
        //关闭时间戳
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false);
        //自定义日期格式
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        mapper.setDateFormat(sdf);
        try {
            return mapper.writeValueAsString(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
